<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>添加书籍</title>
    <link rel="stylesheet" href="element-ui/theme-chalk/index.css">
</head>
<body>

<div id="app" class="container">

    <h3>添加书籍</h3>
    <hr>

    <form>
        <div class="form-group">
            <label>书名</label>
            <input type="text" class="form-control" v-model="book.name" placeholder="书名" required>
        </div>

        <div class="form-group">
            <label>作者</label>
            <input type="text" class="form-control" v-model="book.author" placeholder="作者" required>
        </div>

        <div class="form-group">
            <label>价格</label>
            <input type="number" class="form-control" v-model="book.price" placeholder="价格" required>
        </div>

        <button type="button" class="btn btn-primary" @click="doSave">添加</button>
        <a href="book-list.html" class="btn btn-default">返回</a>
    </form>

</div>

<!-- 引入组件库 -->
<script src="bootstrap/js/vue.min.js"></script>
<script src="bootstrap/js/vue.min.js"></script>
<script>
    var vm = new Vue({
        el:'#app',
        data: {
            book: {
                name:'',
                author:'',
                price:'',
            }
        },
        methods: {
            //处理提交保存事件
            doSave(){
                $.post('/book/save',this.book,function (result) {
                    if (result.code === 0){
                        alert('添加书籍成功！')
                        //跳转到列表页面
                        location.href= 'book-list.html';
                    }else {
                        alert(result.msg);
                    }
                },'json');
            }
        }
    })
</script>

</body>
</html>